/**
 * Cs340 Fatboy Mafia Team
 */
package fatboy.hypeerweb;

import junit.framework.Assert;

/**
 * The Interior-Node State.  
 * An interior node must have an empty list of up/down pointers.
 * If a child (which is an edge or last node) is added to a node, that node becomes an interior node.  
 * An interior node may or may not have a child which is an EdgeNode.
 * An interior node may or may not have an active parent.
 * (An interior node will have a height that is less than or equal to the 
 * height of the "complete" hypercube.)
 * 
 * @author Ilya Vinogradov
 * 
 * @domain a singleton instance
 */
class InteriorNodeState extends NodeState {

	/* (non-Javadoc)
	 * @see fatboy.hypeerweb.NodeState#findInsertionPoint()
	 */
	public Node findInsertionPoint(Node thisNode) {
		//System.out.println(thisNode);
		Node surfaceOrLast = getSurfaceOrLastNode(thisNode);

		return surfaceOrLast.getNodeState().findInsertionPoint(surfaceOrLast);
	}

	protected Node getSurfaceOrLastNode(Node thisNode) {
		Node maxNeighbor = thisNode.getMaximumNeighbor();
	/*	if(debugger++ == 101){
			System.out.println("this: " + thisNode + "\nmaxNeighbor: " + maxNeighbor);
			System.exit(0);
		}*/
		return maxNeighbor.getNodeState().getSurfaceOrLastNode(maxNeighbor);
	}

	public boolean hasEdgeChild(Node thisNode) {
		Node child = thisNode.getChild();
		//System.out.println(child.getAddress());
		if (child.getNodeState().getType() == NodeType.EDGE_NODE) {
			return true;
		}
		return false;
	}

	public boolean hasParent(Node thisNode) {
		if (thisNode.getParent() == Node.nullNode) {
			return false;
		}
		return true;
	}

	public NodeAddress getFirstUpDownNodeAddress(Node thisNode) {
		//return thisNode.getMaximumNeighbor().getAddress();
		return null;
	}
	
	protected NodeType getType() {
		return NodeType.INTERIOR_NODE;
	}

	@Override
	public void assertNodeStateIsCorrect(Node thisNode) {
		Assert.assertTrue(thisNode.getPointers().isEmpty());
		//Assert.assertTrue(thisNode.getChild().getNodeType() == NodeType.EDGE_NODE || thisNode.getChild().getNodeType() == NodeType.LAST_NODE);
	}
}
